const Controller = require('egg').Controller;
// const Mock = require("mockjs")
// const { leases } = Mock.mock({
// 	"leases|200":[{
// 		"title":"@ctitle(3,8)",
// 		"type": /(false|true)/,
// 		"price|1-99": 1,
// 		"sort|10-300":1,
// 		"allPrice|1-99":1,
// 		"area":"@city(true)"
// 	}]
// })
class LeaseController extends Controller {
	async leases() {
		// leases.forEach(item => {
		// 	this.app.mysql.insert('lease', item)
		// })
		const {
			ctx
		} = this
		const data = await ctx.service.lease.leases()
		ctx.body = {
			code: 1,
			data
		}
	}
	async delLeases() {
		const {
			ctx
		} = this
		const data = await ctx.service.lease.delLeases()
		if (data.affectedRows >= 1) {
			ctx.body = {
				code: 1,
				message: '删除成功'
			}
		} else {
			ctx.body = {
				code: 0,
				message: '删除失败'
			}
		}
	}
	async addLeases() {
		const {
			ctx
		} = this
		const data = await ctx.service.lease.addLeases()
		if (data.affectedRows >= 1) {
			ctx.body = {
				code: 1,
				message: '添加成功'
			}
		} else {
			ctx.body = {
				code: 0,
				message: '添加失败'
			}
		}
	}
	async editLeases() {
		const {
			ctx
		} = this
		const data = await ctx.service.lease.editLeases()
		if (data.affectedRows >= 1) {
			ctx.body = {
				code: 1,
				message: '编辑成功'
			}
		} else {
			ctx.body = {
				code: 0,
				message: '编辑失败'
			}
		}
	}
	async editType() {
		const {
			ctx
		} = this;
		const data = await ctx.service.lease.editType()
		if (data.affectedRows >= 1) {
			ctx.body = {
				code: 1,
				message: '修改状态成功'
			}
		} else {
			ctx.body = {
				code: 0,
				message: '修改状态失败'
			}
		}
	}
}

module.exports = LeaseController;